import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.bcel.classfile.JavaClass;
import org.jdom.Element;

import diplomovka.context.Context;
import diplomovka.filesLoader.JarFilesLoader;
import diplomovka.graphCreator.GraphCreator;
import diplomovka.outputCreator.OutputCreator;
import diplomovka.outputCreator.xmi.XmiOutputCreator;
import diplomovka.subgraphSearcher.componentsFinder.SubgraphSearcher;


public class TempMainClass {

	/**
	 * @param args
	 */
	public static void main(String[] args) {	
		if (!loadCommandLineParameters(args))
			return;
		
		System.out.println("Process started...");
		List<String> jarFilesNames = new ArrayList<String>();
		jarFilesNames.add("c:/diplomovka/SearchedProject/dist/SearchedProject.jar");
		JarFilesLoader filesLoader = new JarFilesLoader();
		List<Class> loadedClasses = filesLoader.loadClassesFromJarFiles(jarFilesNames);
		List<JavaClass> loadedByteCodes = filesLoader.getLoadedByteCodes();
		Map<String, Element> loadedConfigs = filesLoader.loadConfigsFromJarFiles(jarFilesNames);
		
		GraphCreator graphCreator = new GraphCreator();
		List<Object> graph = graphCreator.createGraphFromLoadedFiles(loadedClasses, loadedByteCodes, loadedConfigs);
		
		SubgraphSearcher subgraphSearcher = new SubgraphSearcher();
		Map<String, List<Object>> filteredGraph = subgraphSearcher.searchComponentsInGraph(graph);
		
		OutputCreator outputCreator = new XmiOutputCreator();
		outputCreator.createOutput(filteredGraph);
		System.out.println("Process succesfully finished!");
	}

	private static boolean loadCommandLineParameters(String[] args) {
		if (args.length != 1)
			return false;
		
		Context.getInstance().setProjectName(args[0]);
		return true;
	}
}
